<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>书籍列表</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
        }
        .container {
            width: 80%;
            margin: 30px auto;
            background: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        h1 {
            text-align: center;
            color: #333;
        }
        .search-form {
            margin-bottom: 20px;
            text-align: center;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }
        table th, table td {
            border: 1px solid #ddd;
            padding: 12px;
            text-align: center;
        }
        table th {
            background-color: #333;
            color: #fff;
        }
        table tr:nth-child(even) {
            background-color: #f9f9f9;
        }
        .btn {
            display: inline-block;
            padding: 6px 12px;
            font-size: 14px;
            font-weight: bold;
            text-align: center;
            text-decoration: none;
            border-radius: 4px;
            margin: 2px;
            cursor: pointer;
            border: none;
        }
        .btn-info {
            background-color: #17a2b8;
            color: #fff;
        }
        .btn-warning {
            background-color: #ffc107;
            color: #212529;
        }
        .btn-danger {
            background-color: #dc3545;
            color: #fff;
        }
        .btn-primary {
            background-color: #007bff;
            color: #fff;
            font-size: 16px;
            padding: 10px 20px;
            text-align: center;
        }
        .btn:hover {
            opacity: 0.8;
        }
        .btn:focus {
            outline: none;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>书籍列表</h1>

    <!-- 搜索表单 -->
    <form action="/books/search" method="get" class="search-form">
        <input type="text" name="name" placeholder="书名" />
        <input type="text" name="category" placeholder="分类" />
        <input type="text" name="author" placeholder="作者" />
        <button type="submit" class="btn btn-primary">搜索</button>
    </form>

    <table>
        <thead>
        <tr>
            <th>ID</th>
            <th>书名</th>
            <th>分类</th>
            <th>作者</th>
            <th>价格</th>
            <th>销量</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <!-- 遍历书籍列表 -->
        <tr th:each="book : ${books}">
            <td th:text="${book.id}"></td>
            <td th:text="${book.name}"></td>
            <td th:text="${book.category}"></td>
            <td th:text="${book.author}"></td>
            <td th:text="${book.price} + ' 元'"></td>
            <td th:text="${book.sales}"></td>
            <td>
                <!-- 查看、修改和删除书籍的链接 -->
                <a th:href="@{'/books/' + ${book.id}}" class="btn btn-info">查看</a>
                <a th:href="@{'/books/update/' + ${book.id}}" class="btn btn-warning">编辑</a>
                <a th:href="@{'/books/delete/' + ${book.id}}"
                   class="btn btn-danger"
                   th:onclick="'return confirm(\'确定要删除这本书吗？\');'">删除</a>
            </td>
        </tr>
        </tbody>
    </table>
    <a href="/books/add" class="btn btn-primary">添加新书</a>
</div>
</body>
</html>
